﻿using NUnit.Framework;
using System;
using System.Xml;

namespace Sasa.QualityTools.CodeAnalysis.Common.Tests.Unit
{
    [TestFixture]
    public class XmlNodeExtensionTest
    {
        [Test]
        public void GetValueOrDefaultShouldReturnDefaultValueWhenNodeIsNull()
        {
            Assert.AreEqual("default", XmlNodeExtension.GetValueOrDefault(null, "default"));
        }

        [Test]
        public void GetValueOrDefaultShouldReturnNodeValue()
        {
            var document = new XmlDocument();
            document.LoadXml("<root attr='node value'/>");
            var node = document.SelectSingleNode("/root/@attr");
            Assert.AreEqual("node value", node.GetValueOrDefault("default"));
        }

        [Test]
        public void GetInnerTextOrDefaultShouldReturnDefaultValueWhenNodeIsNull()
        {
            Assert.AreEqual("defalut", XmlNodeExtension.GetInnerTextOrDefault(null, "defalut"));
        }

        [Test]
        public void GetInnerTextOrDefalutShouldReturnNodeValue()
        {
            var document = new XmlDocument();
            document.LoadXml("<root>value</root>");
            var node = document.SelectSingleNode("/root");
            Assert.AreEqual("value", node.GetInnerTextOrDefault("value"));
        }
    }
}
